home *** CD-ROM | disk | FTP | other *** search
- /*
- * The original copyright owners of the accompanying source code files have
- * agreed to place such code into the public domain. Accordingly, anyone
- * who receives or obtains a copy of such source code is freely entitled to
- * reproduce, use and otherwise exploit such code (including the right to
- * make derivative works), at his/her own risk and expense, without any
- * obligation or liability to the original copyright owners.
- *
- * We would appreciate (but do not require) that the following message be
- * included in any derivative works:
- *
- * "Portions of this program were developed by Peter Broadwell, Rob Myers
- * and Robin Schaufler while working in Silicon Valley."
- *
- * The accompanying source code files and related documentation materials
- * are distributed on an "AS IS" basis, without any warranties or
- * guarantees of any kind. All implied warranties, including the implied
- * warranties of merchantability and of fitness for any particular purpose,
- * are expressly disclaimed.
- */
- #include "gl.h"
- #include "colors.h"
- #include "sounds.h"
-
- #include <sys/types.h>
- #include <sys/times.h>
- #include "timeb.h"
-
- struct timeb tb_start, tb_end; /* timer blocks */
- extern int maldbug;
-
- char * membuf[256];
- long memuse[256];
- long memufre[256];
- extern long fishPop;
- extern long numgups;
-
- #ifdef MALDEBUG
- #define Bzero(a,b) { char *q=(a), *r=(b); \
- if(maldbug) printf("bzeroing(0x%x,0x%x)\n",q,r); \
- bzero(q,r);}
- #else
- #define Bzero(a,b) bzero(a,b)
- #endif /* MALDEBUG */
-
- #undef BUSY
- #define BUSY 1
- #define INT int
- #define testbusy(p) ((INT)(p)&BUSY)
- #define clearbusy(p) ((INT)(p)&~BUSY)
-
- union store {
- union store *ptr;
- int dummy[1];
- int calloc; /*calloc clears an array of integers*/
- };
-
- gffree(ap)
- register char * ap;
- {
- #ifdef FUDGE
- #define FUDGE
- register union store *p = (union store *)ap;
- register long sz;
-
- /* mallocs info is just before cell */
- --p;
- sz = (char *)clearbusy(p->ptr) - ap;
-
- Bzero(ap,sz);
- if(sz<256) {
- *((char **)ap) = membuf[sz];
- membuf[sz] = (char *)ap;
- if(memufre[sz] == 0) {
- if(maldbug)
- printf("gffree'ing %d bytes\n",sz);
- }
- memufre[sz] += 1;
- return;
- }
- #endif /* FUDGE */
- free(ap);
- }
-
- char *
- gfmalloc(sz)
- long sz;
- {
- register char * retval;
-
- if(sz<256) {
- if(memuse[sz] == 0) {
- if(maldbug)
- printf("gfmalloc'ing %d bytes\n",sz);
- }
- memuse[sz] += 1;
- if(membuf[sz] != 0) {
- retval = membuf[sz];
- membuf[sz] = *(char **)retval;
- return retval;
- }
- }
- return (char *)malloc(sz);
- }
-
- /*
- Store the start time for each kind of sounds and don't bother to
- start another copy of it if it couldn't have expired yet...
- */
-
- typedef struct sndBndl {
- long nexttime;
- long duration;
- } sndBndl;
-
- sndBndl snds[MAX_SOUND] = {
- {0, 0 /* dummy pad slot */ },
- {0, BUG_EYE_LENGTH },
- {0, LAY_EGGS_LENGTH },
- {0, MUNCH_LENGTH },
- };
-
- void
- playSong(char *sname)
- {
- char buf[200];
-
- sprintf(buf, "playaiff %s/%s&", SOUND_DIR, sname);
- system(buf);
- }
-
- void
- doSound(int snd)
- {
- struct tms tmsbuf;
- long now;
- char buf[200];
-
- switch(snd) {
- case BUG_EYE:
- case MUNCH:
- case LAY_EGGS:
- now = times(&tmsbuf);
- if(snds[snd].nexttime < now) {
- switch(snd) {
- case BUG_EYE: playSong("heartBeat.aiff");
- break;
- case MUNCH: playSong("munch1.aiff");
- break;
- case LAY_EGGS: playSong("newEggs.aiff");
- break;
- }
- snds[snd].nexttime = snds[snd].duration + now;
- }
- break;
- default: printf("doSound: got bad arg >%d<\n", snd);
- break;
- }
- }
-
- drawOrig()
- {
- pushmatrix();
- scale(100.0,100.0,100.0);
- fishColor(BOWL_COLOR);
- movei(-40,0,0);
- drawi(40,0,0);
- /* drawi(40,20,0); /* */
- cmovi(40,0,0);
- charstr("x");
- movei(0,-40,0);
- drawi(0,40,0);
- /* drawi(20,40,0); /* */
- cmovi(0,40,0);
- charstr("y");
- movei(0,0,-40);
- drawi(0,0,40);
- /* drawi(20,0,40); /* */
- cmovi(0,0,40);
- charstr("z");
- popmatrix();
- }
-
- drawBowl()
- {
- pushmatrix();
- scale(100.0,100.0,100.0);
- fishColor(BOWL_COLOR);
-
- translate(0.0,0.0,-50.0);
- circi(0,0,50);
- translate(0.0,0.0,100.0);
- /*
- translate(0.0,0.0,50.0);
- */
- circi(0,0,50);
-
- popmatrix();
- }
-
- drawBox()
- {
- pushmatrix();
- scale(100.0,100.0,100.0);
- fishColor(BOWL_COLOR);
-
- movei(-40,-40,-40);
- drawi(-40, 40,-40);
- drawi(-40, 40, 40);
- drawi(-40,-40, 40);
- drawi(-40,-40,-40);
-
- movei( 40,-40,-40);
- drawi( 40, 40,-40);
- drawi( 40, 40, 40);
- drawi( 40,-40, 40);
- drawi( 40,-40,-40);
-
- movei(-40, 40,-40);
- drawi( 40, 40,-40);
- drawi( 40, 40, 40);
- drawi(-40, 40, 40);
- drawi(-40, 40,-40);
-
- movei(-40,-40,-40);
- drawi( 40,-40,-40);
- drawi( 40,-40, 40);
- drawi(-40,-40, 40);
- drawi(-40,-40,-40);
-
- popmatrix();
- }
-
- #define dy 14
- #define y 300
- display_time (name, iteration, count)
- char *name;
- register long iteration, count;
- {
- register int millisecs;
- char charbuf[100];
-
- millisecs = 1000 * (tb_end.time - tb_start.time) +
- tb_end.millitm - tb_start.millitm;
- if (millisecs == 0) millisecs = 1;
-
- fishWritemask(FOREGROUND);
- pushmatrix();
- ortho2(0.0,500.0,0.0,500.0);
- cursoff ();
- frontbuffer (TRUE);
- color (WHITE);
-
- sprintf (charbuf,"Times for %s: iteration %d",name, iteration);
- cmov2i (150,y);
- charstr (charbuf);
-
- sprintf (charbuf," %d in %d.%02d seconds",
- count,millisecs/1000,(millisecs%1000)/10);
- cmov2i (150,y-dy);
- charstr (charbuf);
-
- sprintf (charbuf," %d msecs per call",millisecs/count);
- cmov2i (150,y-2*dy);
- charstr (charbuf);
-
- sprintf (charbuf," %d per second",count*1000/millisecs);
- cmov2i (150,y-3*dy);
- charstr (charbuf);
-
- sprintf (charbuf," %d total fish",fishPop);
- cmov2i (150,y-4*dy);
- charstr (charbuf);
-
- sprintf (charbuf," %d total gups",numgups);
- cmov2i (150,y-5*dy);
- charstr (charbuf);
-
- frontbuffer (FALSE);
- curson ();
- popmatrix();
- }
-
- ftime (tb)
- register struct timeb *tb;
- {
- long s60;
- struct tms tmsbuf;
-
- s60 = times(&tmsbuf);
- tb -> time = s60/60;
- tb -> millitm = (s60%60) * 1000 / 60;
- return s60;
- }
-
- #ifdef NOTDEF
- #include <gl2/gltypes.h>
- #include <gl2/globals.h>
- #endif
-
- dumpglobjs()
- {
- #ifdef NOTDEF
- register long i;
- register hashrec *h;
-
- printf("dumping:\n");
- for(i=0;i<256;i++) {
- h = gl_hashtable[i];
- if(h) printf("\n");
- for(; h; h = h->link) {
- printf(" 0x%x",h->obj);
- }
- }
- printf("\n");
- #endif
- }
-
-